package com.yangli.leecode.mashib.interview;

import java.util.Arrays;

/**
 * @Description
 * @Author liyang
 * @Date 2023/2/3 16:10
 */
public class Seven {
    public static void main(String[] args){
        System.out.println(Seven.su(new int[]{3, 4, 5, 8, 2, 7}, 3));

    }

    //贪心
    public static int su(int[] arr, int k){
        if (arr == null || arr.length == 0 || arr.length == 1) {
            return 0;
        }
        Arrays.sort(arr);
        int ans = 0;
        int r = 1;
        while (r < arr.length ) {
            if (arr[r] - arr[r - 1] <= k) {
                r += 2;
                ans++;
            } else {
                r++;
            }
        }
        return ans;
    }
}
